﻿
using System.Collections.Generic;
using UnityEngine;
using UIFramework;

public partial class UIBase : IUIBase
{    
    public const string NAME = "UIBase";
    public Transform RootTrans;
    public bool IsRepeat = false;

    public virtual EUICanvas GetUICanvas()
    {        
        return EUICanvas.Middle;
    }

    #region UI 外部(UIManager)调用
    public sealed override void InitializeUI(Transform uiRoot)
    {
        RootTrans = uiRoot;
        InitDepth();
        OnInitialize(uiRoot);
    }

    public sealed override void ShowUI(params object[] paras)
    {
        OnShow(paras);
        DoShowAnimation();
    }

    public sealed override void CloseUI(System.Action callback)
    {
        OnClose();
        DoCloseAnimation(callback);
    }

    public sealed override void DestoryUI()
    {
        OnDestory();
    }

    //public void ChangeLanguage(EAppLanguage language)
    //{
    //    OnChangeLanguage(language);
    //}
    #endregion

    #region UI 内部流程
    protected virtual void DoShowAnimation()
    {
        //打开动画
    }

    protected virtual void DoCloseAnimation(System.Action callback)
    {
        //关闭动画
        //动画做完后需要执行回调
        if (callback != null)
        {
            callback();
        }
    }

    protected virtual void OnInitialize(Transform uiRoot)
    {
        
    }

    protected virtual void OnShow(params object[] paras)
    {

    }

    /// <summary>
    /// 设置动态生成的物体的层级
    /// 调用时机是在OnShow之后
    /// </summary>
    protected virtual void OnDepthChange(int depthDelta)
    {

    }

    protected virtual void OnClose()
    {

    }

    protected virtual void OnDestory()
    {

    }

    //protected virtual void OnChangeLanguage(EAppLanguage language)
    //{
    //    switch (language)
    //    {
    //        default:
    //            break;
    //    }
    //}
    #endregion
}

public abstract class IUIBase
{
    public abstract void InitializeUI(Transform uiRoot);

    public abstract void ShowUI(params object[] paras);

    public abstract void SetDepth(int depth);

    public abstract void CloseUI(System.Action callback);

    public abstract void DestoryUI();
}